package com.yc.jpyy.base.service;

import java.util.List;
import java.util.Map;

import com.yc.jpyy.base.util.PageBean;

public abstract class BaseService {
	/**
	 * 分页
	 * @param paramsMap
	 */
	protected static void checkPageParamsMap(Map<String, Object> paramsMap){
		String currentPage_ = paramsMap.get("PageNum") == null ? "1" : String.valueOf(paramsMap.get("PageNum"));
		currentPage_ = currentPage_.trim().equals("") ? "1" : currentPage_;
		int currentPage = Integer.parseInt(currentPage_);
		String pageSize_ = paramsMap.get("PageSize") == null ? "10" : String.valueOf(paramsMap.get("PageSize"));
		pageSize_ = pageSize_.trim().equals("") ? "10" : pageSize_;
		int pageSize = Integer.parseInt(pageSize_);
		
		int begin = (currentPage-1) * pageSize;
		int endNum = begin + pageSize;
		
		paramsMap.put("beginNum", (currentPage-1) * pageSize + 1);
		paramsMap.put("endNum", endNum);
	}
	
	/**
	 * sqlserver分页:
	 * @param paramsMap
	 */
	protected static void checkParamsMapForPage(Map<String, Object> paramsMap){
		String currentPage_ = paramsMap.get("PageNum") == null ? "1" : String.valueOf(paramsMap.get("PageNum"));
		currentPage_ = currentPage_.trim().equals("") ? "1" : currentPage_;
		int currentPage = Integer.parseInt(currentPage_);
		String pageSize_ = paramsMap.get("PageSize") == null ? "10" : String.valueOf(paramsMap.get("PageSize"));
		pageSize_ = pageSize_.trim().equals("") ? "10" : pageSize_;
		int pageSize = Integer.parseInt(pageSize_);	
		int topNum = pageSize;
		paramsMap.put("beginNum", (currentPage-1) * pageSize);
		paramsMap.put("topNum", topNum);
	}
	
	protected static PageBean getPageBean(List list,int counts,int pagesize,int pagenum){
		PageBean pagebean = new PageBean();
		pagebean.setList(list);
		pagebean.setCurrentPage(pagenum);
		pagebean.setPageSize(pagesize);
	    pagebean.setAllRow(counts);
		if(counts % pagesize > 0){
			pagebean.setTotalPage(counts / pagesize + 1);
		}else{
			pagebean.setTotalPage(counts / pagesize);
		}
		pagebean.paginationTool(pagebean.getCurrentPage(),pagebean.getTotalPage());
		return pagebean;
	}


}
